<template>
  <div class="address">
    <van-nav-bar left-text="新增地址" left-arrow @click-left="onClickLeft" />
    <van-address-edit :show-area="false" @save="onSave" />
  </div>
</template>

<script>
import { address_add } from "../../api";
export default {
  mounted() {
    this.id = window.localStorage.getItem("userid");
    console.log(this.id);
  },
  data() {
    return {
      id: 0,
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSave(address) {
      console.log(address);
      address_add({
        userid: this.id,
        address: address.addressDetail,
        phone: address.tel,
        name: address.name,
      }).then((res) => {
        console.log(res.data);
      });
      this.$router.push('/addresslist')
    },
  },
};
</script>

<style scoped>
::v-deep .van-nav-bar__text {
  color: black;
  font-weight: 800;
  font-size: 16px;
}
</style>